from PyQt4.QtGui import QWidget
from PyQt4 import QtCore,QtGui
import pyqtgraph as pg
from KModel.KSingleStock import KSingleStock

## The only required methods are paint() and boundingRect() 
## (see QGraphicsItem documentation)
class KChartBaseDisplayItem(pg.GraphicsObject):
	'''the base class of all base display items'''
	def __init__(self, stockobject):
		pg.GraphicsObject.__init__(self)
		self.m_stock=stockobject # maintain a stock object inside of each item,which is the data source of this display item
		self.PrepareRenderPicture()
		
	def UpdateDisplay(self):
		self.PrepareRenderPicture() #regenerate the picture
		self.update(self.boundingRect()) # update this item
		self.informViewBoundsChanged() # inform its viewbox to update,otherwise the viewbox related can't update(like axis)		
		
	def paint(self, p, *args):
		p.drawPicture(0, 0, self.picture)


	def boundingRect(self):
		## boundingRect _must_ indicate the entire area that will be drawn on
		## or else we will get artifacts and possibly crashing.
		## (in this case, QPicture does all the work of computing the bouning rect for us)
		return QtCore.QRectF(self.picture.boundingRect())
